/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bef.dtgenerator.core.rtgen.managergen;

import com.inspur.edp.bef.dtgenerator.core.BefCoreGenCtx;
import com.inspur.edp.bef.dtgenerator.core.rtgen.accessorcreatorgen.BefAccessorCreatorGenerator;
import com.inspur.edp.bef.dtgenerator.core.rtgen.entitygen.BefEntityGenerator;
import com.inspur.edp.bef.dtgenerator.core.rtgen.lcpgenerator.LcpClassGenerator;
import com.inspur.edp.bef.dtgenerator.core.rtgen.variable.BEVariableGenerator;
import com.inspur.edp.caf.generator.BaseGenerator;
import com.inspur.edp.caf.generator.composite.CompositeGeneratorContext;
import com.inspur.edp.cef.designtime.api.variable.CommonVariableEntity;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorcreatorgen.AccessorCreatorGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.EntityGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.mgrGenerator.DataManagerImplGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.mgrGenerator.ManagerGenerator;

public class BefManagerGenerator extends ManagerGenerator {

  private String mgrClassName;

  public BefManagerGenerator(BefCoreGenCtx parentContext) {
    super(parentContext);
  }

  private BefCoreGenCtx getParentContext() {
    return (BefCoreGenCtx) super.ParentContext;
  }


  @Override
  protected EntityGenerator createEntityGenerator() {
    return new BefEntityGenerator(getParentContext());
  }

  private BefManagerGenContext getBefManagerGenContext() {
    return (BefManagerGenContext) getMgrGenContext();
  }

  @Override
  protected CompositeGeneratorContext createCompositeContext() {
    BefManagerGenContext context = new BefManagerGenContext();
    getParentContext().setBefManagerGenContext(context);
    context.setProjContext(this.ParentContext);
    return context;
  }

  @Override
  protected DataManagerImplGenerator createMgrImplGenerator() {
    BeMgrClassGenerator mgrImpl = new BeMgrClassGenerator(getBefManagerGenContext());
    mgrClassName = mgrImpl.getClassName();
    return mgrImpl;
  }

  @Override
  protected void addExtendCompositeItemGenerators(
      java.util.ArrayList<BaseGenerator> compositeItemGenerators) {
    LcpClassGenerator lcpGen = LcpClassGenerator
        .Create((BefCoreGenCtx) ((ParentContext instanceof BefCoreGenCtx) ? ParentContext : null),
            mgrClassName);
    compositeItemGenerators.add(lcpGen);
//		compositeItemGenerators.add(new B4QueryDtmAssGenerator(getMgrGenContext()));
//		compositeItemGenerators.add(new B4RetrieveDtmAssGenerator(getMgrGenContext()));
  }

  @Override
  protected AccessorCreatorGenerator createAccessorCreatorImplGenerator() {
    return new BefAccessorCreatorGenerator(getMgrGenContext());
  }
}
